package com.qf.ssm.service.Impl;

/**
 * @author hzy
 * @DATE 2021/2/26
 */

import com.qf.ssm.entity.order.EvluationReply;
import com.qf.ssm.entity.order.OrderReview;
import com.qf.ssm.mapper.order.OrderReviewMapper;
import com.qf.ssm.service.EvalManageService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单评价详情管理
 */
@Service
public class EvalManageServiceImpl implements EvalManageService {
    @Resource
    OrderReviewMapper orderReviewMapper;
    @Override
    public ResponseResult<List<OrderReview>> selectEvalList() {
        ResponseResult<List<OrderReview>>result;
        List<OrderReview> orderReviews = orderReviewMapper.selectAllEva();
        if (orderReviews!=null){
            result=ResponseResult.success(orderReviews);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<OrderReview>selectEvalByNumbs(String orderNums){
        ResponseResult<OrderReview>result;
        OrderReview orderReview = orderReviewMapper.selectByNumbs(orderNums);
        if (orderReview!=null){
            result=ResponseResult.success(orderReview);
        }else {
            result = ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<List<OrderReview>> selectEvalByMessage(String goodMessage) {
        ResponseResult<List<OrderReview>>result;
        List<OrderReview> orderReviews = orderReviewMapper.selectByMessage(goodMessage);
        if (orderReviews!=null){
            result=ResponseResult.success(orderReviews);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> OrderReviewAudit(EvluationReply evluationReply) {
        ResponseResult<Integer>result;
        Integer insert = orderReviewMapper.insertByOrid(evluationReply);
        if (insert>0){
            result=ResponseResult.success(insert);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> OrderReviewMofidyByorId(EvluationReply evluationReply) {
        ResponseResult<Integer>result;
        int i = orderReviewMapper.updateReviewByOrid(evluationReply);
        if (i>0){
            result=ResponseResult.success(i);
        }else{
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> insertBuyerReview(OrderReview orderReview) {
        ResponseResult<Integer>result;
        int insert = orderReviewMapper.insert(orderReview);
        if (insert>0){
            result=ResponseResult.success(insert);
        }else {
            return ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> updateStatusByorID(int orId, int status) {
        ResponseResult<Integer>result;
        int i = orderReviewMapper.updateBystatus(orId, status);
        if (i>0){
            result=ResponseResult.success(i);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }
}
